package com.tiantian.quanminxiu.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tiantian.quanminxiu.R;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by admin on 2016/1/14.
 */
public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.MyViewHolder>
{

    private Activity activity;
    private JSONArray list;
    public UserListAdapter(Activity activity, JSONArray list){
        this.activity = activity;
        this.list = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                activity).inflate(R.layout.dialog_userlist_item, parent,
                false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position)
    {
        JSONObject user = list.optJSONObject(position);
        holder.txtUserName.setText(user.optString("NickName"));
  /*      u.setCoin(value.optInt("Coin"));
        u.setIsAdmin(value.optBoolean("IsAdmin"));
        u.setUser_ID(value.optInt("User_ID"));
        u.setIsRoomGuardian(value.optBoolean("RoomGuardian"));
        u.setSex(value.optInt("Sex"));
        u.setLevel(value.optInt("Level"));
        u.setNickName(value.optString("NickName"));
        u.setIsAnchor(value.optBoolean("IsAnchor"));*/
    }

    @Override
    public int getItemCount()
    {
        return list.length();
    }

    class MyViewHolder extends RecyclerView.ViewHolder
    {
        TextView txtGiftTime,txtUserName,txtGiftInfo;

        public MyViewHolder(View view)
        {
            super(view);
            txtGiftTime = (TextView) view.findViewById(R.id.txtGiftTime);
            txtUserName = (TextView) view.findViewById(R.id.txtUserName);
            txtGiftInfo = (TextView) view.findViewById(R.id.txtGiftInfo);
        }
    }

}
